<?php

class Page {

    /**
     * restful动作
     *
     * @param array $actions 动作源数组，分为get和post两部分
     * @return void
     */
    public static function action(array $actions) {
        
        // 如果没有带action的querystring，则直接退出函数
        if (empty(get('action'))) return;
        
        // 获取请求访问、请求action名称
        $method = strtolower(Get::method());
        $action = get('action');

        // 查看是否存在此接口，如果不存在，则报错退出
        if (!is_callable($actions[$method][$action])) {
            End::eNoInterface();
        }

        // 定义function主体
        $function = $actions[$method][$action];

        // 执行function
        $function();
    }

    /**
     * 开始，输出开始html标签
     *
     * @param string $title
     * @return void
     */
    public static function start(string $title = '管理页面') {
        echo "
        <!DOCTYPE html>
        <html lang='zh-CN'>
            <head>
                <meta charset='utf-8'>
                <meta http-equiv='X-UA-Compatible' content='IE=edge'>
                <title>$title</title>
                <script src='https://cdn.bootcss.com/vue/2.5.22/vue.min.js'></script>
                <script src='https://cdn.bootcss.com/element-ui/2.4.11/index.js'></script>
                <script src='https://cdn.bootcss.com/lodash.js/4.17.11/lodash.min.js'></script>
                <script src='/assets/script/macro.js'></script>
                <script src='/assets/script/mixin.js'></script>
                <script src='/assets/script/component.js'></script>
                <link href='https://cdn.bootcss.com/element-ui/2.4.11/theme-chalk/index.css' rel='stylesheet'>
                <link href='/assets/style/macro.css' rel='stylesheet'>
                <link href='/assets/style/index.css' rel='stylesheet'>
                <link href='/assets/style/page.css' rel='stylesheet'>
                <link href='/assets/style/third.css' rel='stylesheet'>
            </head>
            <body>
                <div id='app'>
        ";
    }

    /**
     * 结束，输出结束html标签
     *
     * @return void
     */
    public static function end() {
        echo '</div></body></html>';
    }
}
